package com.yeung.alo

import scala.io.StdIn

object 抓捕孔连顺 {
  def main(args: Array[String]): Unit = {
    val MOD = 99997867
    var count = 0;
    val split = StdIn.readLine().split(" ").map(_.toInt)
    val D = split(1)
    val N = split(0)
    val positions = StdIn.readLine().split(" ").map(_.toInt)
    for (pos <- 0 until (positions.length)) {
      val X = positions(pos) + D //安全距离
      var low = pos + 1 //从某一点的右边一个点开始找
      var high = N - 1 //最后一个点
      while (low <= high) {
        val mid = (low + high) / 2
        if (positions(mid) > X)
          high = mid - 1
        else
          low = mid + 1
      }
      //找到了安全距离内的最远点下标
      if (high - pos - 1 > 0) {
        //计算组合数 capacity(n,2)
        val a = (high - pos) % MOD
        val b = (high - pos - 1)
        count += (a * b) / 2
      }
    }
    println(count % MOD)
  }

}
